package com.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.entity.FieldsEntity;

@Repository
public class FieldsDaoImpl extends GenericDaoImpl<FieldsEntity> implements FieldsDao {

	public FieldsEntity getFieldsById(Integer id) {
		return getById(FieldsEntity.class, id);
	}

	public List<FieldsEntity> getAllFields() {
		return getAll(FieldsEntity.class);
	}

	public List<FieldsEntity> getFieldsByStatusId(int idStatus) {
		String hql = "From FieldsEntity where statusEntity.idStatus = :idStatus";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter("idStatus", idStatus);
		return query.list();
	}

	public int getMaxFields() {
		String hql = "Select max(idFields) From FieldsEntity";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		return (Integer) query.uniqueResult();
	}

	public FieldsEntity getFieldsByIssueId(int idIssue) {
		String hql = "Select fieldsEntity From IssueEntity as fields where fields.idIssue=:idIssue";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter("idIssue", idIssue);
		return (FieldsEntity) query.uniqueResult();
	}

	public List<FieldsEntity> getFieldsByDeveloperEmail(String email) {
		String hql = "From FieldsEntity where userEntityByIdAuthor.emailAddress = :email";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter("email", email);
		return query.list();
	}
	// clazz.getSimpleName().substring(0, 1).toLowerCase() +
	// clazz.getSimpleName().substring(1)

}
